﻿using HRIS.Browser.UI.Framework;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HRIS.Browser.UI.ConfigReader
{
    public class ConfigProvider
    {
        private static ConfigProvider _instance;

        private LoginBase<By> _login;
        private MenuBase<By> _topMenu;

        private ConfigProvider()
        { }

        public MenuBase<By> TopMenu
        {
            get
            {
                if (_topMenu == null)
                {
                    LoadTopMenuConfig();
                }

                return _topMenu;
            }
        }

        public LoginBase<By> Login
        {
            get
            {
                if (_login == null)
                {
                    LoadLoginConfig();
                }

                return _login;
            }
        }

        public static ConfigProvider GetInstance()
        {
            if (_instance == null)
            {
                _instance = new ConfigProvider();
            }

            return _instance;
        }

        private void LoadTopMenuConfig()
        {
            _topMenu = new MenuBase<By>();
            _topMenu.MenuItem = HRISEnums.MenuItems.TopMenu;
            _topMenu.Element = By.CssSelector("#RadMenu1");
            _topMenu.SubMenus = new List<MenuBase<By>>();

            _topMenu.SubMenus.Add(new MenuBase<By>()
            {
                MenuItem = HRISEnums.MenuItems.MIS,
                Element = By.CssSelector("#RadMenu1 > div.rmScrollWrap.rmRootGroup > ul > li:nth-child(5) > a > span"),
                SubMenus = new List<MenuBase<By>>() {
                    new MenuBase<By>()
                    {
                        MenuItem = HRISEnums.MenuItems.ClockInClockOut,
                        Element = By.LinkText("Clock in Clock out status")
                    }
                }
            });

            //   _topMenu.SubMenus[HRISEnums.MenuItems.MIS].SubMenus.Add();

            //_topMenu.SubMenus.Add(Enums.TopMenuItems.PersonalData, By.CssSelector("#RadMenu1 > div.rmScrollWrap.rmRootGroup > ul > li:nth-child(1).rmItem.rmFirst > a"));
            //_topMenu.SubMenus.Add(Enums.TopMenuItems.EmploymentData, By.CssSelector("#RadMenu1 > div.rmScrollWrap.rmRootGroup > ul > li:nth-child(2) > a > span"));
            //_topMenu.SubMenus.Add(Enums.TopMenuItems.SelfTask, By.CssSelector("#RadMenu1 > div.rmScrollWrap.rmRootGroup > ul > li:nth-child(3) > a > span"));
            //_topMenu.SubMenus.Add(Enums.TopMenuItems.PMS, By.CssSelector("#RadMenu1 > div.rmScrollWrap.rmRootGroup > ul > li:nth-child(4) > a > span"));
            //_topMenu.SubMenus.Add(Enums.TopMenuItems.MIS, By.CssSelector("#RadMenu1 > div.rmScrollWrap.rmRootGroup > ul > li:nth-child(5) > a > span"));
        }

        private void LoadLoginConfig()
        {
            _login = new LoginBase<By>();
            _login.btnLogin = By.CssSelector("#LocalizedButton1");
            _login.txtPassword = By.CssSelector("#txtPwd");
            _login.txtUserId = By.CssSelector("#txtID");
            _login.Element = By.CssSelector("#tblleftpillar");
        }
    }
}
